package com.lmx.repoDomain.tmodel;


import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import com.lmx.repoDomain.tmodel.business.User;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToMany;
import io.katharsis.resource.annotations.JsonApiToOne;


/**
 * 房间表
 */
@JsonApiResource(type = "room")
@Table(name = "tnb_room")
@Entity
//@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Room extends BaseEntity {
	private Integer seq;//

	private String remark;// 备注

	private String name;

	private String area;// 房屋面积

	private User lastUpdateUser;// 更新操作者userid

	private Integer createDateTime;// 创建时间

	private User createUser;

	private Integer lastUpdateDateTime;// 更新时间

	private String facility;// 设施

	private String isGroupFlag;// 是否有护理组

	private String price;// 房屋价格

	private Dicttype roomType;// 房屋类型

	private NurseGroup nurseGroup;// 所属护理组

	private Dicttype oldType;// 老人护理等级

	private Dicttype orientation;// 房屋朝向

	private String scannerFlag;// 用于标识房间0 楼梯 过道 1

	private String scannerID;// 扫描器id

	private Floor floor;

	private Short isPublicFlag;// 用于区分是否为公共区域 0 为房间 1为公共区域

	//private List<Bed> beds;// 所包床位

	private Dicttype publicType; // 公共区域类型

	private Integer bedNum;// 床位数

	private String toilet;// 卫生间

	private String balcony;// 阳台
	
	private List<Bed> beds;

	private Device scanner;// 华米扫描器

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "scanner_id", nullable = true, foreignKey = @ForeignKey(name = "null"))
	public Device getScanner() {
		return scanner;
	}

	public void setScanner(Device scanner) {
		this.scanner = scanner;
	}
	
	@Transient
	@JsonApiToMany
	@JsonApiIncludeByDefault
	public List<Bed> getBeds() {
		return beds;
	}

	public void setBeds(List<Bed> beds) {
		this.beds = beds;
	}

	@Column(name = "bed_num")
	public Integer getBedNum() {
		return bedNum;
	}

	public void setBedNum(Integer bedNum) {
		this.bedNum = bedNum;
	}

	@Column(name = "toilet")
	public String getToilet() {
		return toilet;
	}

	public void setToilet(String toilet) {
		this.toilet = toilet;
	}

	@Column(name = "balcony")
	public String getBalcony() {
		return balcony;
	}

	public void setBalcony(String balcony) {
		this.balcony = balcony;
	}

	@Column(name = "seq")
	public Integer getSeq() {
		return seq;
	}

	public void setSeq(Integer seq) {
		this.seq = seq;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "publictype_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getPublicType() {
		return publicType;
	}

	public void setPublicType(Dicttype publicType) {
		this.publicType = publicType;
	}

	@Column(name = "public_flag")
	public Short getIsPublicFlag() {
		return isPublicFlag;
	}

	public void setIsPublicFlag(Short isPublicFlag) {
		if (isPublicFlag == null)
			isPublicFlag = 0;
		this.isPublicFlag = isPublicFlag;
	}

//	@JsonApiToMany
//	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "room")
//	public List<Bed> getBeds() {
//		return beds;
//	}
//
//	public void setBeds(List<Bed> beds) {
//		this.beds = beds;
//	}

	@JsonApiToOne
	// @JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "nursegroup_id", foreignKey = @ForeignKey(name = "null"))
	@Fetch(FetchMode.JOIN)
	public NurseGroup getNurseGroup() {
		return nurseGroup;
	}

	public void setNurseGroup(NurseGroup nurseGroup) {
		this.nurseGroup = nurseGroup;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "floor_id", foreignKey = @ForeignKey(name = "null"))
	public Floor getFloor() {
		return floor;
	}

	public void setFloor(Floor floor) {
		this.floor = floor;
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "area")
	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "lastUpdateUser_id", foreignKey = @ForeignKey(name = "null"))
	public User getLastUpdateUser() {
		return lastUpdateUser;
	}

	public void setLastUpdateUser(User lastUpdateUser) {
		this.lastUpdateUser = lastUpdateUser;
	}

	@Column(name = "createDateTime")
	public Integer getCreateDateTime() {
		return createDateTime;
	}

	public void setCreateDateTime(Integer createDateTime) {
		this.createDateTime = createDateTime;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "createUser_id", foreignKey = @ForeignKey(name = "null"))
	public User getCreateUser() {
		return createUser;
	}

	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	@Column(name = "lastUpdateDateTime")
	public Integer getLastUpdateDateTime() {
		return lastUpdateDateTime;
	}

	public void setLastUpdateDateTime(Integer lastUpdateDateTime) {
		this.lastUpdateDateTime = lastUpdateDateTime;
	}

	@Column(name = "facility")
	public String getFacility() {
		return facility;
	}

	public void setFacility(String facility) {
		this.facility = facility;
	}

	@Column(name = "isGroupFlag")
	public String getIsGroupFlag() {
		return isGroupFlag;
	}

	public void setIsGroupFlag(String isGroupFlag) {
		this.isGroupFlag = isGroupFlag;
	}

	@Column(name = "price")
	public String getPrice() {
		return price;
	}

	public void setPrice(String price) {
		this.price = price;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "roomType_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getRoomType() {
		return roomType;
	}

	public void setRoomType(Dicttype roomType) {
		this.roomType = roomType;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "Old_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getOldType() {
		return oldType;
	}

	public void setOldType(Dicttype oldType) {
		this.oldType = oldType;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "orientation_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getOrientation() {
		return orientation;
	}

	public void setOrientation(Dicttype orientation) {
		this.orientation = orientation;
	}

	@Column(name = "scannerFlag")
	public String getScannerFlag() {
		return scannerFlag;
	}

	public void setScannerFlag(String scannerFlag) {
		this.scannerFlag = scannerFlag;
	}

	@Column(name = "scannerid")
	public String getScannerID() {
		return scannerID;
	}

	public void setScannerID(String scannerID) {
		this.scannerID = scannerID;
	}

	public Room() {
	}

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
}
